package edu.strategy.single.defaults;

import java.awt.Color;
import java.awt.geom.Rectangle2D;

import robocode.AdvancedRobot;
import robocode.Event;
import edu.strategy.single.Single;

public class TeancumPassiveDefaultStrategy extends Single {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	static double currentDirection;
	static Rectangle2D fieldrect;
	static double currentEnergy;
	static double currentVBound;
	
	public TeancumPassiveDefaultStrategy(AdvancedRobot advancedRobot) {
		super(advancedRobot);
	}
	
	@Override
	public void prepare() {
		currentEnergy = 100;
		super.getAdvancedRobot().setTurnRadarRight(Double.POSITIVE_INFINITY);
		Color blue = Color.blue;
		super.getAdvancedRobot().setColors(blue, blue, blue);
		super.getAdvancedRobot().setAdjustRadarForRobotTurn(true);
	}

	public boolean out(double angle, double c)
	{
		return !(new Rectangle2D.Double(18, 18, super.getAdvancedRobot().getBattleFieldWidth()-36D,  super.getAdvancedRobot().getBattleFieldHeight()-36D)).contains(Math.sin(angle)*c+super.getAdvancedRobot().getX(), Math.cos(angle)*c+super.getAdvancedRobot().getY());
	}
	
	@Override
	public void work() {
		super.used();
		super.getAdvancedRobot().setMaxVelocity(currentVBound);
		if (out(super.getAdvancedRobot().getHeadingRadians(),currentDirection))
			currentDirection = -currentDirection;
		super.getAdvancedRobot().setAhead(currentDirection);
		super.getAdvancedRobot().execute();
	}

	@Override
	public void work(Event e) {
		work();
	}

	@Override
	public String toString() {
		return "TeancumPassiveDefaultStrategy";
	}

}
